<?php
require_once("../../../config.inc.php");
$isReloadable = false;
require_once("../../../app/_inc/include.php");
require_once("moduleFunction.php");

$errMsg = "";
if(isset($_REQUEST["reqtype"]) && $_REQUEST["reqtype"] == "save"){
	$errMsg .= subModIns();
	$module = sxREQUEST("module");
	$subModule = sxREQUEST("sub_module");
	$functionalArea = sxREQUEST("functional_area");
	$description = sxREQUEST("description");
	$note = sxREQUEST("note");
	$doc_name = sxREQUEST("doc_name");
}else{
	$module = sxREQ('mod');
	$functionalArea = sxREQ('fa');
	$subModule = "";
	$description = "";
	$note = "";
	$doc_name = "";
}
if($module==''){
	$url = $_SESSION[USEROBJ]->getHistory(0, true).
		"&msg=".urlencode(_t("var 'mod' missing")); 
	serverRedir($url);
}
if($functionalArea==''){
	$url = $_SESSION[USEROBJ]->getHistory(0, true).
		"&msg=".urlencode(_t("var 'fa' missing")); 
	serverRedir($url);
}

//output HTML
$aOpz = array("kMenu"=>'mod.pro', "isReloadable"=>false);
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript">
	function objFrmSave(){
		try{
			var objFrm = document.getElementById("objFrm");
			var objDA =  document.getElementById("sub_module");
			var objDe =  document.getElementById("description");
			var objMessArea =  document.getElementById("messArea");
			var errMsg = "";
			if(objDe.value == ""){
				errMsg += "<?php echo _t("description missing.")?><br>";
				objDe.focus();
			}
			if(objDA.value == ""){
				errMsg += "<?php echo _t("name missing.")?><br>";
				objDA.focus();
			}
			if(errMsg == ""){
				objFrm.submit();
			}else{
				objMessArea.innerHTML = errMsg;
			}
		}catch(e){
			raiseError(e.description, "save new sub-module");
		}			
	}
</script>
  
<?php
echo(bodyHTML($aOpz));
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"subModIns.php\" method=\"POST\" enctype=\"multipart/form-data\">\n");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">\n");
echo("<input type=\"hidden\" name=\"xsn\" value=\"".XSN."\">\n");
echo("<input type=\"hidden\" name=\"module\" id=\"module\" value=\"$module\">\n");
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
echo("<tr>" .
			"<td class=\"labl01\" width='10%'>Module</td>" .
			"<td class=\"text01\" width='90%'>$module</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">Functional-Area</td>" .
			"<td class=\"text01\">\n<select name='functional_area'>\n");
$sSQL = "SELECT * FROM functional_area WHERE module = '$module'";
$objSDAO->query($sSQL,'fa');
while($rowFA=$objSDAO->fetch('fa')) {
	echo("<option value=\"".$rowFA['functional_area']."\" ".
		(($rowFA['functional_area']==$functionalArea)?'SELECTED':'').">"
		.$rowFA['functional_area']." - ".$rowFA['description']."</option>\n");
}
echo(		"</td>" .
		"</tr>\n</table>");

$aCmd = array("insMD"=>array("pag"=>"javascript:objFrmSave()",
										"title"=>_t("save data"),
										"text"=>_t("save")
										),
					"back"=>array("pag"=>$objUser->getHistory(0,false),
										"title"=>$objUser->getHistoryText(0),
										"text"=>$objUser->getHistoryText(0)
										)
					);
echo(commandsHTML($aCmd));	
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\" border='0'>\n");
echo("<tr>" .
			"<td class=\"labl01\">Name (*)</td>" .
			"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"sub_module\" id=\"sub_module\" maxlength=\"4\" size='4' value=\"$subModule\"></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Description")." (*)</td>" .
			"<td class=\"text01\"><input class=\"inpt01\" type=\"text\" name=\"description\" id=\"description\" maxlength=\"80\" size=\"80\" value=\"".sxHE($description)."\"></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Note")."</td>" .
			"<td class=\"text01\"><textarea class=\"inpt01\" name=\"note\" id=\"note\" cols=\"80\" rows=\"8\">".sxHE($note)."</textarea></td>" .
		"</tr>\n");
echo("</table>");
echo(commandsHTML($aCmd));
echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
exit();